package com.xpsoft.oa.service.admin.impl;


import java.text.DecimalFormat;
import java.util.Date;

import org.apache.commons.lang.StringUtils;

import com.xpsoft.core.service.impl.BaseServiceImpl;
import com.xpsoft.core.util.DateUtil;
import com.xpsoft.oa.dao.admin.AdminArticleSendDao;
import com.xpsoft.oa.model.admin.AdminArticleSend;
import com.xpsoft.oa.service.admin.AdminArticleSendService;

public class AdminArticleSendServiceImpl extends BaseServiceImpl<AdminArticleSend> implements AdminArticleSendService{
	private AdminArticleSendDao dao;
	
	public AdminArticleSendServiceImpl(AdminArticleSendDao dao) {
		super(dao);
		this.dao=dao;
	}

	@Override
	public String getNewArticleNo() {
		String firstCode = "R";
		String nowYear = DateUtil.format(new Date(), "yyyy");
		String search = firstCode+nowYear;
		String newNo="";
		String contractNo = dao.getMaxNo(search);
		if(StringUtils.isBlank(contractNo)){
			newNo = search+ "001";
		}else{
			DecimalFormat df = new DecimalFormat("000");
			newNo = search + df.format(1 + Integer.parseInt(contractNo.substring(search.length(),contractNo.length())));
		}
		return newNo;
	}

}